/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package coba.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.kernel.exception.SystemException;

import coba.model.Solicitud;
import coba.service.SolicitudLocalServiceUtil;
import coba.service.base.SolicitudServiceBaseImpl;

/**
 * The implementation of the Solicitud remote service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link coba.service.SolicitudService} interface.
 *
 * <p>
 * This is a remote service. Methods of this service are expected to have security checks based on the propagated JAAS credentials because this service can be accessed remotely.
 * </p>
 *
 * @author rodri042
 * @see coba.service.base.SolicitudServiceBaseImpl
 * @see coba.service.SolicitudServiceUtil
 */
public class SolicitudServiceImpl extends SolicitudServiceBaseImpl {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never reference this interface directly. Always use {@link coba.service.SolicitudServiceUtil} to access the Solicitud remote service.
	 */

	public List<Solicitud> findByFechaItinerarioAndFechaBaja(int anio, int mes, int dia, Date fechaBaja) throws SystemException {
		
		Calendar cal = GregorianCalendar.getInstance();
		cal.set(Calendar.YEAR, anio);
		cal.set(Calendar.MONTH, mes);
		cal.set(Calendar.DAY_OF_MONTH, dia);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		
		//return this.solicitudPersistence.findByFechaItinerarioAndFechaBaja(cal.getTime(), null);
		try {
			DynamicQuery query = DynamicQueryFactoryUtil.forClass(Solicitud.class);

			query.add(PropertyFactoryUtil.forName("fechaItinerario")
					.gt(new SimpleDateFormat("dd/MM/yyyy").parse("01/01/2000")));

			query.add(PropertyFactoryUtil.forName("fechaItinerario")
					.lt(new SimpleDateFormat("dd/MM/yyyy").parse("01/01/2020")));
			
			query.add(PropertyFactoryUtil.forName("fechaBaja").isNull());

			
			return SolicitudLocalServiceUtil.dynamicQuery(query);

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}

	public List<Solicitud> findByFechaItinerarioDesdeAndFechaItinerarioHasta(Date fechaItinerarioDesde, Date fechaItinerarioHasta)
			throws SystemException {

		return SolicitudLocalServiceUtil.findByFechaItinerarioDesdeAndFechaItinerarioHasta(fechaItinerarioDesde, fechaItinerarioHasta);

	}

}
